﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Silver3D.Math;

namespace Silver3D.Tests.Math
{
    /// <summary>
    /// Summary description for Matrix44Tests
    /// </summary>
    [TestClass]
    public class Matrix44Tests
    {
        public Matrix44Tests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void Matrix44_Multiplication()
        {
            Matrix44 a = new Matrix44(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
            Matrix44 b = new Matrix44(a);

            Assert.AreEqual(new Matrix44(
                90, 100, 110, 120,
                202, 228, 254, 280,
                314, 356, 398, 440,
                426, 484, 542, 600), a * b);
        }

        [TestMethod]
        public void Matrix44_Inverse()
        {
            Matrix44 m = new Matrix44(1, 2, 3, 4, 4, 1, 7, 8, 9, 10, 1, 12, 0, 0, 0, 1);
            Assert.IsTrue(m.IsInvertible);
            Assert.AreEqual(142.0, m.Determinant);
            Matrix44 im = m.Inverse;

            Matrix44 expected = new Matrix44(
                -0.485915492958, 0.197183098592, 0.0774647887324, -0.56338028169,
                0.415492957746, -0.183098591549, 0.0352112676056, -0.619718309859,
                0.218309859155, 0.056338028169, -0.0492957746479, -0.732394366197,
                0, 0, 0, 1);

            Assert.IsTrue(im.IsEquivalent(expected));
        }
    }
}
